<?php

class Output {

	public static function reload() {
	    self::redirect(Url::composeUrl('./', $_GET));
	}

	public static function redirect($pageUrl) {
		header('Location: ' . $pageUrl);
		exit;
	}

	public static function customHeader(MimeType $oMime) {
		header('Content-Type: ' . $oMime->toString());
	}

	public static function htmlHeader() {
		self::checkIsHeaderCalled();
		header('Content-Type: text/html; charset=' . Settings::config('system')->get('site', 'encoding'));
	}

	public static function rssHeader() {
		self::checkIsHeaderCalled();
		header('Content-Type: text/xml; charset=' . Settings::config('system')->get('site', 'encoding'));
	}

	public static function plaintextHeader() {
		self::checkIsHeaderCalled();
		header('Content-Type: text/plain; charset=' . Settings::config('system')->get('site', 'encoding'));
	}

    private static $isHeaderCalled = false;

	private static function checkIsHeaderCalled() {

		static $debug_firstHeaderCall = null;

		if (self::isHeaderCalled()) {
			throw new Exception('Header already called. First call ' . $debug_firstHeaderCall . ', last call ' . Debug::getCallPoint(2));
		} else {
		    $debug_firstHeaderCall = Debug::getCallPoint(2);
		}

		self::$isHeaderCalled = true;
	}

    public static function isHeaderCalled() { return self::$isHeaderCalled; }

}

?>